Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Sheet8 * File : src/app/(site)/s/[slug]/page.tsx9 * Module : app10 * Repository : https://git.spboucher.ai/sheet11 * Project Website : https://sheet.spboucher.ai12 * Created : 2026-11-1713 * Last Modified : 2026-11-1714 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { plainMath } from "@/renderer/mathtext";44import type { Metadata } from "next";45import Link from "next/link";46import { notFound, permanentRedirect } from "next/navigation";47import { cache } from "react";48import { getLocale } from "@/i18n/server";49import { dict } from "@/i18n/dict";50import { env } from "@/lib/env";51import { getPublished, relatedPublished } from "@/server/sheets";52import { SheetReader } from "@/components/site/sheet-page";53import { SheetGrid } from "@/components/site/sheet-card";54import { ShareButtons, ViewBeacon } from "@/components/site/controls";5556export const dynamic = "force-dynamic";5758const T = dict({59 share: ["Partager cette fiche", "Share this sheet"], pdf: ["Télécharger en PDF", "Download as PDF"], related: ["À lire ensuite", "Read next"], tags: ["Mots-clés", "Tags"],60 alsoIn: ["Aussi disponible en", "Also available in"], fr: ["français", "French"], en: ["anglais", "English"],61 cite: ["Citer cette fiche", "Cite this sheet"],62});6364const load = cache(async (slug: string, locale: "fr" | "en") => (/^[a-z0-9-]{1,96}$/.test(slug) ? getPublished(slug, locale) : null));6566export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {67 const { slug } = await params;68 const r = await load(slug, await getLocale());69 if (!r || "redirect" in r) return { title: "Sheet", robots: { index: false } };70 const s = r.sheet, url = `${env.appUrl}/s/${s.slug}`;71 const languages = Object.fromEntries([[s.locale, url], ...s.translations.map((x) => [x.locale, `${env.appUrl}/s/${x.slug}`])]);72 // Without a custom image, Next adds the generated one (opengraph-image.tsx) to the page metadata by itself.73 const images = s.ogAssetId ? { images: [{ url: `${env.appUrl}/media/${s.ogAssetId}` }] } : {};74 return {75 title: s.seoTitle ?? s.title, description: s.seoDescription ?? plainMath(s.summary),76 alternates: { canonical: s.canonicalUrl ?? url, languages },77 authors: [{ name: s.doc.metadata.author, url: `${env.appUrl}/about` }],78 keywords: s.tags.map((x) => x.name),79 openGraph: { type: "article", url, title: s.seoTitle ?? s.title, description: s.seoDescription ?? plainMath(s.summary), publishedTime: s.publishedAt, modifiedTime: s.updatedAt, authors: [s.doc.metadata.author], locale: s.locale === "fr" ? "fr_CA" : "en_CA", ...images },80 twitter: { card: "summary_large_image", title: s.seoTitle ?? s.title, description: s.seoDescription ?? plainMath(s.summary), ...(s.ogAssetId ? { images: [`${env.appUrl}/media/${s.ogAssetId}`] } : {}) },81 };82}8384export default async function SheetPage({ params }: { params: Promise<{ slug: string }> }) {85 const { slug } = await params;86 const locale = await getLocale();87 const r = await load(slug, locale);88 if (!r) notFound();89 if ("redirect" in r) permanentRedirect(`/s/${r.redirect}`);90 const s = r.sheet, t = T(locale), url = `${env.appUrl}/s/${s.slug}`;91 const related = await relatedPublished(s.sheetId, locale);92 const jsonLd = {93 "@context": "https://schema.org", "@type": "TechArticle", headline: s.title, description: plainMath(s.summary), inLanguage: s.locale, url, mainEntityOfPage: url,94 datePublished: s.publishedAt, dateModified: s.updatedAt, isAccessibleForFree: true, timeRequired: `PT${s.readingMinutes}M`,95 author: { "@type": "Person", name: s.doc.metadata.author, url: `${env.appUrl}/about` }, publisher: { "@type": "Person", name: "Simon-Pierre Boucher", url: `${env.appUrl}/about` },96 keywords: s.tags.map((x) => x.name).join(", "), about: s.topics.map((x) => (s.locale === "en" ? x.name_en : x.name_fr)),97 proficiencyLevel: s.doc.metadata.level, citation: s.doc.sources.map((c) => ({ "@type": "CreativeWork", name: c.title, ...(c.doi ? { sameAs: `https://doi.org/${c.doi}` } : c.url ? { url: c.url } : {}) })),98 };99 return (100 <>101 {/* JSON-LD: serialised by the server from stored fields; "<" is escaped so no markup can break out. */}102 <script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd).replace(/</g, "\\u003c") }} />103 <SheetReader doc={s.doc} locale={locale} publishedAt={s.publishedAt} updatedAt={s.updatedAt} readingMinutes={s.readingMinutes} topics={s.topics.map((x) => ({ slug: x.slug, name: locale === "en" ? x.name_en : x.name_fr }))}>104 <div className="no-print mt-8 grid gap-6 border-t border-line pt-6">105 {s.translations.length > 0 && (106 <p className="text-sm text-muted">{t.alsoIn}{" "}107 {s.translations.map((x) => <Link key={x.locale} href={`/s/${x.slug}`} hrefLang={x.locale} className="font-semibold text-accent underline-offset-4 hover:underline">{x.locale === "fr" ? t.fr : t.en}</Link>)}108 </p>109 )}110 <section aria-labelledby="h-share">111 <h2 id="h-share" className="eyebrow mb-3">{t.share}</h2>112 <div className="flex flex-wrap items-center gap-2">113 <ShareButtons title={s.title} url={url} />114 {s.pdfAssetId && <a className="btn btn-sm" href={`/media/${s.pdfAssetId}`} download>{t.pdf}</a>}115 </div>116 </section>117 {s.tags.length > 0 && (118 <section aria-labelledby="h-tags">119 <h2 id="h-tags" className="eyebrow mb-3">{t.tags}</h2>120 <ul className="flex flex-wrap gap-2">{s.tags.map((x) => <li key={x.slug}><Link href={`/search?tag=${x.slug}`} className="inline-flex min-h-9 items-center rounded-full border border-line px-3 text-sm text-muted hover:text-ink">{x.name}</Link></li>)}</ul>121 </section>122 )}123 {related.length > 0 && (124 <section aria-labelledby="h-related">125 <h2 id="h-related" className="mb-4 font-display text-2xl font-semibold tracking-tight">{t.related}</h2>126 <SheetGrid sheets={related} locale={locale} />127 </section>128 )}129 </div>130 </SheetReader>131 <ViewBeacon slug={s.slug} locale={s.locale} />132 </>133 );134}135